package com.jpa.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jpa.pojo.Permission;
 
@Repository 
public interface PermissionDao extends BaseDao<Permission, Long> {
	
	@Query(value = "select p.name,p.*  from  Permission p left join role_permission rp on  rp.permission_id=p.id left join role r on rp.role_id=r.rid left join user_role ur on ur.rid=r.rid WHERE ur.uid=:uid", nativeQuery = true)
	List<Permission> findPermissions(@Param(value = "uid") long uid);

	@Query(value = "select p  from Permission  p where p.name=:name", nativeQuery = true)
	Permission findByName(@Param(value = "name") String name);

	List<Permission> findById(long id);
	  
}
